from django.db import models

# Create your models here.
from huamei_mall.utils.BaseModel import BaseModel

'''定义首页广告模型类'''


class ContentCategory(BaseModel):
    """广告类别表"""
    name = models.CharField(max_length=50,
                            verbose_name='广告类别名称')

    key = models.CharField(max_length=50,
                           verbose_name='类别识别键名')

    class Meta:
        db_table = 'tb_content_category'
        verbose_name = '广告内容类别'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

"""广告内容表"""
class Content(BaseModel):
    #ContentCategory：  指定模型类ContentCategory映射的表是 Content的主表
    category = models.ForeignKey(ContentCategory,
                                 on_delete=models.PROTECT,   #阻止删除主表中被外键应用的数据
                                 verbose_name='类别'
                                 )
    title = models.CharField(max_length=100,
                             verbose_name='标题')

    url = models.CharField(max_length=300,
                           verbose_name='内容链接')


    #null如果为True，表示允许为空，默认值是False
    #blank如果为True，则该字段允许为空白，默认值是False
    image = models.ImageField(null=True,
                              blank=True,
                              verbose_name='图片')

    text = models.TextField(null=True,
                            blank=True,
                            verbose_name='内容')

    sequence = models.IntegerField(verbose_name='排序')

    status = models.BooleanField(default=True,
                                 verbose_name='是否展示')

    class Meta:
        db_table = 'tb_content'
        verbose_name = '广告内容'
        verbose_name_plural = verbose_name
    def __str__(self):
        return  self.category.name + ':' + self.title